**********************************************************
* Information, Candidate Selection, and the Quality of Representation: Evidence from Nepal
* Replication .do File for Appendix Results Tables
**********************************************************
cls
clear 

version 15.1


* install commands
ssc install reghdfe
ssc install lincom
ssc install estout
ssc install orth_out

* Set Working Directory
cd "~/Dropbox/nepal_localgovt/analysis/"
global repl_dir "jop/replication archive"
global rinf_dir "${repl_dir}"
do "${rinf_dir}/rinf_program.do" 
cd "${repl_dir}"
* set number  of iterations for exact p-values
local num_iter = 5000

* load dataset
use nepal_final_cleaned.dta, clear




* Table A8: Summary Statistics
estpost su wardid_unique_sumstats seatid_sumstats ticket_id 
su party_rank survey_rank_ties age female  ticket ticket_p_notranked_first vshare partyjoin_years committee_member ///
 relatives_elections relatives_politics business 


* Table A9: Balance Table
*** Balance Table with covaraites as dependent variables
* col 1 
regress female treat_elect treat_loyal treat_comp , noconstant r
test treat_elect =treat_loyal= treat_comp
* col 2
regress age treat_elect treat_loyal treat_comp  , noconstant r
test treat_elect =treat_loyal= treat_comp
* col 3
regress monthlyincome treat_elect treat_loyal treat_comp  , noconstant r
test treat_elect =treat_loyal= treat_comp
* col 4
regress durationofcurrentposition treat_elect treat_loyal treat_comp , noconstant r
test treat_elect =treat_loyal= treat_comp
* col 5
regress party_rank treat_elect treat_loyal treat_comp  , noconstant r
test treat_elect =treat_loyal= treat_comp
* col 6
regress survey_rank_ties treat_elect treat_loyal treat_comp  , noconstant r
test treat_elect =treat_loyal= treat_comp 
* Multinomial logit mentioned in table notes
mlogit treat female age lincome durationofcurrentposition party_rank survey_rank_ties , noconstant baseoutcome(1) 



* Table A10: Determinants of Party Ranking:
* col 1
areg party_rank survey_rank_ties, absorb(seattype) cluster(seatid)
* col 2
areg party_rank survey_rank_ties age female, absorb(seattype) cluster(seatid)
* col 3
areg party_rank survey_rank_ties age female   partyjoin_years committee_member relatives_elections relatives_politics, absorb(seattype) cluster(seatid)
* col 4
areg party_rank survey_rank_ties age female   business lincome  highestlevelofeducation , absorb(seattype) cluster(seatid)
* col 5
areg party_rank survey_rank_ties age female partyjoin_years committee_member relatives_elections relatives_politics  business lincome  highestlevelofeducation , absorb(seattype) cluster(seatid)





* Table A11: Differences Between Prospective Candidates by Deviation Direction
global summary_variables age female partyjoin_years ///
			 committee_member relatives_elections ///
			 relatives_politics  business monthlyincome ///
			 highestlevelofeducation num_seats

gen num_seats = 4 if climb_sign==-1 
replace num_seats = 28 if climb_sign==0
replace num_seats = 20 if climb_sign==1
label variable num_seats "Number of Seats"

preserve
keep if first_rank==1
orth_out ${summary_variables}   ///
		, by(climb_sign) test  pcompare   
restore

orth_out ${summary_variables}   ///
		, by(climb_sign) test  pcompare 


* Table A12: Correlates of Candidate Nominations: Quantiles of % of Survey Votes Received
* col 1
areg first_rank first_rank_survey, absorb(seattype) cluster(seatid)
* col 2
areg first_rank first_rank_survey age female partyjoin_years committee_member relatives_elections relatives_politics  business lincome  highestlevelofeducation , absorb(seattype) cluster(seatid)
* 	create above median
gen above_50= percent_survey_votes >0.5
gen below_50_top_ranked = percent_survey_votes <=0.5 & first_rank_survey
* col 3
areg first_rank above_50 below_50_top_ranked, absorb(seattype) cluster(seatid)
test above_50 == below_50_top_ranked
* col 4
areg first_rank above_50 below_50_top_ranked age female partyjoin_years committee_member relatives_elections relatives_politics  business lincome  highestlevelofeducation , absorb(seattype) cluster(seatid)
test above_50 == below_50_top_ranked
* 	create terciles
xtile tercile = first_rank_survey_percent if first_rank_survey_percent !=0,  nq(3)
replace tercile = 0 if missing(tercile)
tab tercile, gen(tercile_)
* col 5
areg first_rank tercile_2 tercile_3 tercile_4, absorb(seattype) cluster(seatid)
test tercile_2 == tercile_4
* col 6
areg first_rank tercile_2 tercile_3 tercile_4 age female partyjoin_years committee_member relatives_elections relatives_politics  business lincome  highestlevelofeducation , absorb(seattype) cluster(seatid)
test tercile_2 == tercile_4




* Table A13: Correlates of Voter Rank
* col 1
areg  first_rank_survey age female, absorb(seattype) cluster(seatid)
* col 2
areg  first_rank_survey age female   partyjoin_years committee_member relatives_elections relatives_politics, absorb(seattype) cluster(seatid)
* col 3
areg  first_rank_survey age female   business lincome  highestlevelofeducation , absorb(seattype) cluster(seatid)
* col 4
areg  first_rank_survey age female partyjoin_years committee_member relatives_elections relatives_politics  business lincome  highestlevelofeducation , absorb(seattype) cluster(seatid)






* Table A14: Correlates of Party Rank, Omitting Voter Rank as an Explanatory Variable
* col 1
areg  first_rank age female, absorb(seattype) cluster(seatid)
* col 2 
areg  first_rank age female   partyjoin_years committee_member relatives_elections relatives_politics, absorb(seattype) cluster(seatid)
* col 3
areg  first_rank age female   business lincome  highestlevelofeducation , absorb(seattype) cluster(seatid)
* col 4
areg  first_rank age female partyjoin_years committee_member relatives_elections relatives_politics  business lincome  highestlevelofeducation , absorb(seattype) cluster(seatid)


* Table A15: Treatment Effect without Other Treatments
* col 1 
rinf, esttype(0) dv(ticket_p_notranked_first) iter(`num_iter') treats(treat_elect treat_loyal treat_comp  i.block i.seattype_no) numtreat(3) absorb(" ") cluster(seatid) lr(2) lr1(" ")
reg ticket_p_notranked_first treat_elect treat_loyal treat_comp  i.block i.seattype_no, r cluster(seatid)
* col 2
rinf, esttype(0) dv(ticket_p_notranked_first) iter(`num_iter') treats(treat_elect treat_loyal treat_comp  i.block i.seattype_no  if treat_comp ==0 & treat_loyal==0) numtreat(3) absorb(" ") cluster(seatid) lr(2) lr1(" ")
reg ticket_p_notranked_first treat_elect  i.block i.seattype_no if treat_comp ==0 & treat_loyal==0, r cluster(seatid)
























